#define TRACE
using System;
using System.Diagnostics;
using System.Text;

namespace ErrorDumper.Writing {
    public sealed class TraceExceptionWriter : IExceptionWriter {

        internal static string ToString(DateTimeOffset utc, ExceptionPropertyCollection properties, string content) {
            var builder = new StringBuilder("ErrorDump : " + utc.ToUniversalTime().ToString("s") + "\r\n");

            if (properties != null && properties.Count > 0)
                foreach (var h in properties)
                    builder.AppendLine("\t" + h.Key + "=" + h.Value);

            builder.AppendLine();

            if (!string.IsNullOrWhiteSpace(content))
                builder.AppendLine(content);

            return builder.ToString();
        }

        public string WriteException(ExceptionPropertyCollection properties, string content) {
            var utc = DateTimeOffset.UtcNow;

            Trace.TraceError(ToString(utc, properties, content));

            return "trace:" + utc.ToString("s");
        }
    }
}
